using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.Page
{
	public class SelectCard : BasePage
	{
		public enum SelectCardFromType
		{
			fromChatPage,
			fromProfilePage,
			other
		}
		private const string TAG = "SelectCard";
		private string cuUsername;
		private ChatPageCtrl fromPage;
		private SelectCard.SelectCardFromType fromType;
		private ApplicationBar mBar;
		private ApplicationBarIconButton OkMenuBtn;
		internal Grid LayoutRoot;
		internal panelTitle2Line panelTitle;
		internal DynamicTextBlock TitleDesc;
		internal ContactsView mContactView;
		private bool _contentLoaded;
		public static void StartSelectCard(BasePage originPage, ChatPageCtrl chatpage, string toUsername, SelectCard.SelectCardFromType fromType = SelectCard.SelectCardFromType.fromChatPage)
		{
			originPage.GoToPage("/Source/UI/Chat/Card/SelectCard.xaml", new object[]
			{
				toUsername,
				chatpage,
				fromType
			}, false);
		}
		public SelectCard()
		{
			this.InitializeComponent();
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && Enumerable.Count<object>(object_0) == 3)
			{
				string text = object_0[0] as string;
				this.fromPage = (object_0[1] as ChatPageCtrl);
				this.cuUsername = text;
				this.fromType = (SelectCard.SelectCardFromType)object_0[2];
				if (this.fromType == SelectCard.SelectCardFromType.fromChatPage)
				{
					this.mContactView.set_Height(620.0);
					this.mContactView.mContactViewType = ContactsViewType.CONTACT_VIEW_CLICKTOADD;
					this.panelTitle.strSecondTitle = strings.ChatSelectFriend;
					this.TitleDesc.set_Visibility(1);
					List<string> list = new List<string>();
					list.Add(text);
					ContactsView.resetCheckedList(list);
					this.mContactView.mClickToAddCallBack += new MMUIEvent(this.mContactView_mClickToAddCallBack);
					return;
				}
				this.mContactView.set_Height(540.0);
				this.mContactView.mContactViewType = ContactsViewType.CONTACT_VIEW_CHECKTOADD;
				this.panelTitle.strSecondTitle = strings.Message_ChooseCardReceiver;
				this.TitleDesc.set_Visibility(0);
				this.TitleDesc.Text = string.Format(strings.Message_ChooseCardReceiver_Desc, ContactHelper.getDisplayName(text, null));
				List<string> list2 = new List<string>();
				list2.Add(text);
				ContactsView.resetCheckedList(list2);
				this.mContactView.mItemCheckChanged += new ContactsView.ItemCheckChanged(this.mContactView_mItemCheckChanged);
				base.set_ApplicationBar(this.GetOneIconAppBar());
			}
		}
		private object mContactView_mClickToAddCallBack(object sender, object object_0)
		{
			Contact contact = object_0 as Contact;
			if (contact == null)
			{
				return null;
			}
			if (ContactMgr.getUserType(contact.strUsrName) != ContactMgr.UserType.UserTypeNormal)
			{
				return null;
			}
			CardConfirm.StartCardConfirm(this, this.cuUsername, contact, this.fromPage);
			return null;
		}
		private ApplicationBar GetOneIconAppBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			if (this.mBar != null)
			{
				this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
				this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
			}
			this.OkMenuBtn = new ApplicationBarIconButton(new Uri("/icons/appbar.check.rest.png", 2));
			this.OkMenuBtn.set_Text(strings.COM_Confirm);
			this.OkMenuBtn.add_Click(new EventHandler(this.OkMenuBtn_Click));
			this.OkMenuBtn.set_IsEnabled(false);
			this.mBar.get_Buttons().Add(this.OkMenuBtn);
			return this.mBar;
		}
		private void OkMenuBtn_Click(object sender, EventArgs e)
		{
			List<Contact> checkedItem = ContactsView.getCheckedItem();
			if (checkedItem == null || checkedItem.get_Count() == 0)
			{
				return;
			}
			Contact contact = StorageMgr.contact.method_0(this.cuUsername);
			if (contact == null)
			{
				return;
			}
			CardConfirm.StartCardConfirm(this, checkedItem, contact, this.fromPage);
		}
		private void mContactView_mItemCheckChanged(object sender, object object_0)
		{
			List<Contact> checkedItem = ContactsView.getCheckedItem();
			if (checkedItem.get_Count() == 0)
			{
				this.OkMenuBtn.set_IsEnabled(false);
				return;
			}
			this.OkMenuBtn.set_IsEnabled(true);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/Card/SelectCard.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelTitle = (panelTitle2Line)base.FindName("panelTitle");
			this.TitleDesc = (DynamicTextBlock)base.FindName("TitleDesc");
			this.mContactView = (ContactsView)base.FindName("mContactView");
		}
	}
}
